import time

import requests


def security_url_get(url, time_out = 60, max_retries = 5):
    response = None
    for attempt in range(max_retries):  # 最多重试
        try:
            response = requests.get(url, timeout=time_out)  # 设置超时时间为10秒
            response.raise_for_status()  # 检查HTTP状态码
            break  # 请求成功，跳出重试循环
        except (requests.exceptions.RequestException, requests.exceptions.Timeout) as e:
            print(f"Attempt {attempt + 1} failed for URL {url}: {str(e)}")
            time.sleep(2 ** attempt)  # 指数退避
        except Exception as e:
            print(f"Unexpected error occurred: {str(e)}")
            break
    return response


